CSharpTest.Net
Instance Property
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Interfaces Namespace > Singleton<T> Class : Instance Property

Glossary Item Box

Returns the singleton instance of T

Syntax

Visual Basic (Declaration) 
Public Shared ReadOnly Property Instance As T
C# 
public static T Instance {get;}

Example

Library/Library.Test/TestFactories.cs

C#Copy Code
try
{
    GC.KeepAlive(Singleton<BadObject>.Instance);
    Assert.Fail();
}
catch(ApplicationException ae)
{
    Assert.AreEqual("BadObject", ae.GetBaseException().Message);
}
try
{
    Singleton<BadObject>.Factory.Create();
    Assert.Fail();
}
catch (ApplicationException ae)
{
    Assert.AreEqual("BadObject", ae.GetBaseException().Message);
}
VB.NETCopy Code
Try
    GC.KeepAlive(Singleton(Of BadObject).Instance)
    Assert.Fail()
Catch ae As ApplicationException
    Assert.AreEqual("BadObject", ae.GetBaseException().Message)
End Try
Try
    Singleton(Of BadObject).Factory.Create()
    Assert.Fail()
Catch ae As ApplicationException
    Assert.AreEqual("BadObject", ae.GetBaseException().Message)
End Try

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys